# -*- coding: utf-8 -*-

#mesure de resistance avec alim 1A
import visa
import re
import time
import numpy as np
import matplotlib.pyplot as plt

##Initilazation de la mesure de V: juste identification
AgilentV = visa.instrument("GPIB::2")
print "Mesure de tension", AgilentV.ask("*IDN?")

##Initilazation de la mesure de I: juste identification

KeithleyI = visa.instrument("GPIB::7")
KeithleyI.write("DOK-PRETX")
time.sleep(0.5)
KeithleyI.write("F3X")
KeithleyI.write("S3X")
KeithleyI.write("T5X")
KeithleyI.write("DX")
time.sleep(1)

## Affectation du tableau de données
numit=10
R=np.zeros(numit)


## Mise en place du graphique
plt.ion()
graph,=plt.plot(R)
plt.draw()
plt.autoscale(enable=True)
plt.axis([0, numit, 0.00099, 0.00101])


## Prise des mesures
for i in range(numit):
    I=KeithleyI.ask_for_values("X")
    V=AgilentV.ask_for_values("MEAS:VOLT:DC?")
    R[i]=V[0]/I[0]
    graph.set_ydata(abs(R))
    plt.draw()
    time.sleep(0.3)

## affichage des resultats
print "Moyenne", np.mean(R)*1000 , "mOhm"
print "Variance", np.var(R)*1000 , "mOhm"
raw_input("Press enter when done...")




    

